import {Component, VNode} from "@vue/runtime-core";

export type Option = {
    label: string
    value?: any
    [key: string]: any
}
type OptionProps = {
    children?: string
    value?: string
    label: string
    isLeaf?: string
}
interface Upload{
    action?: string
    showFileList?: boolean
    listType?: "text" | "picture" | "picture-card"
}
interface Select<T>{
    // 附加的下拉菜单数据
    options?: Option[],
    allowCreate?: boolean
    filterable?: boolean,
    // 远程下拉菜单数据
    serviceOptionKey?: string,
    // el-tree：prop配置; 下拉菜单也可以配置
    optionProps?: OptionProps
    popoverReference?: (item?: any)=> VNode
    create?: (serviceOptions: { [key: string]: any[] }, data: T) => void
    checkStrictly?: boolean
    lazy?: boolean
    load?: (node: any, resolve: Function)=> void
    multiple?: boolean
    cacheData?: (data: T)=> {label: string, value: any}[]
}
interface DateTime<T>{
    // 日期选择器 开始提示语
    startPlaceholder?: string,
    // 日期选择器 结束提示语
    endPlaceholder?: string
    // 范围选择时选中日期所使用的当日内具体时刻
    defaultTime?: [Date, Date]
    // maxTime
    maxTime?: string & keyof T
    // minTime
    minTime?: string & keyof T

}
interface Method<T>{
    // 当值发生变化触发的事件
    changeMethod?: (val: any, data: T, enable: {[key in `form-item-${keyof T & string}`]: boolean}
        , changeCallBack: {[key in `${keyof T & string}Create`]: Function}) => void
    // 初始化时触发的事件
    initMethod?: ()=> void
}
export interface FormItem<T> extends Upload, Select<T>, Method<T>, DateTime<T>{
    // 组件名
    component?: "" | "input" | "select" | "inputNumber" | "radioButton" | "radio" | "tree"
        | "popover" | "datePicker" | "checkboxGroup" | "upload" | "uploads" | "tag" | "timeSelect"
        | "switch" | "treeSelect"
    // 映射对象的key值
    prop?: string & keyof T
    // 标题
    label?: string
    // 类型
    type?: "text" | "number" | "textarea" | "datetime" | "date" | "daterange"
    // 提示语
    placeholder?: string
    // 格式转换
    valueFormat?: string
    // label宽度
    labelWidth?: number
    // 内插槽
    inSlot?: (item: any)=> VNode
    // 插槽
    slot?: (item?: any, callFun?: (val: any)=>void)=> VNode
    // 样式
    style?: string
    // 是否必需; 暂未使用该属性
    required?: boolean
    // 检验规则
    rule?: object
    // el组件大小
    size?: "" | "large" | "default" | "small"
    // 最小值
    min?: number,
    // 最大值
    max?: number
    // 文本域行数
    rows?: number
    // 禁用
    disabled?: boolean,
    // 是否启用；是否显示出来
    enable?: boolean
    // 词典key
    dict?: string
    key?: string
}

export type FormTree<T> = Array<Array<FormItem<T>>>



